<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-11-23 09:33
 *
 * Version: 2.0
 */

namespace App\Modules\Coupon\Controllers;


use App\Lib\Facades\FLAuth;
use App\Modules\Coupon\Services\CouponService;
use App\Modules\Coupon\Validators\CouponBarberControllerValidator;
use Flower\Core\Http\BaseController;
use Illuminate\Http\Request;

class CouponBarberController extends BaseController
{
	protected $couponService;
	public function __construct(CouponService $couponService)
	{
		$this->couponService = $couponService;
	}

	public function getRules()
	{
		return CouponBarberControllerValidator::validator();
	}

	/**
	 * 发送优惠券给消费者
	 * @param Request $request
	 * @return mixed
	 * @throws \App\Exceptions\AllValidatorException
	 * @throws \App\Exceptions\NotFoundException
	 */
	public function postToMember(Request $request){
		$result =$this->couponService->postToMember(FLAuth::id(),$request);
		return $this->handleApiResult($result);
	}

	/**
	 * 获取理发师发送的优惠券列表
	 * @param Request $request
	 * @return mixed
	 */
	public function getCouponList(Request $request){
		$storeId = $request->input('store_id');
		$type = $request->input('type',0);
		$isLive = $request->input('is_live',1);
		$result = $this->couponService->getCouponSendListFromBoss($storeId,$type,$isLive);
		
		return $this->handleApiResult($result);
	}

	/**
	 * 会员领取情况列表
	 * @param Request $request
	 * @return mixed
	 */
	public function getReceiveMemberCouponList(Request $request){
		$storeId = $request->input('store_id');
		$userId = FLAuth::id();
		$result = $this->couponService->getReceiveMemberCouponList($storeId,$userId);
		return $this->handleApiResult($result);
	}


	/**
	 * 未领取完的优惠券回收
	 * @param Request $request
	 * @return mixed
	 */
	public function getRecoveryCouponList(Request $request){
		$storeId = $request->input('store_id');
		$userId = FLAuth::id();
		$result = $this->couponService->getRecoveryCouponList($storeId,$userId);
		return $this->handleApiResult($result);
	}
}